package com.guodi.model.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guodi.common.utils.Asserts;
import com.guodi.core.boot.ctrl.BaseController;
import com.guodi.core.tool.api.R;
import com.guodi.model.entity.UeProjectManger;
import com.guodi.model.entity.UeUpdateRecords;
import com.guodi.model.service.ICacheService;
import com.guodi.model.service.IUeUpdateRecordsService;
import com.guodi.model.vo.UeProjectMangerVo;
import com.guodi.model.vo.UeUpdateRecordsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @描述：项目管理-更新记录表控制类
 * @作者: 徐金洲
 * @日期: 2023-05-06
 */
@RestController
@RequestMapping("/UeUpdateRecords")
@Api(value = "API - UeUpdateRecordsController", tags = "更新记录表控制类")
public class UeUpdateRecordsController extends BaseController {

    @Resource
    public IUeUpdateRecordsService ueUpdateRecordsService;

    @Resource
    private ICacheService cacheService;

    /**
     * @描述: 查询更新记录列表
     * @入参: ProjectId
     * @出参: list
     * @作者: 徐金洲
     * @日期: 2023-05-06
     **/
    @PostMapping("/getUpdateRecordsList")
    @ApiOperation(value = "查询更新记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ProjectId", value = "页数", required = true, dataType = "int", paramType = "query")
    })
    public R getUpdateRecordsList(String projectId) {
        Asserts.isEmpty(projectId, "项目ID必传");
        //定义list接收返回值
        List<UeUpdateRecords> list = null;
        if(StringUtils.isNotBlank(projectId)){
            list = ueUpdateRecordsService.getUpdateRecordsList(projectId);
        }
        return R.data(toVo(list));
    }

    /**
     * @作者: 徐金洲 2023/05/08
     * @描述: 转VO, 转字典
     */
    private List<UeUpdateRecordsVo> toVo(List<UeUpdateRecords> list) {
        List<UeUpdateRecordsVo> listVo = new ArrayList<>();
        for (UeUpdateRecords row : list) {
            UeUpdateRecordsVo vo = new UeUpdateRecordsVo();
            BeanUtils.copyProperties(row, vo);
            vo.setProcessedByName(cacheService.getUserName(Long.parseLong(vo.getProcessedBy())));
            listVo.add(vo);
        }
        return listVo;
    }


}
